using System;
using System.Collections;
using System.Windows.Forms;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;
using Northwind;

namespace ORMappingWithEUSS
{
	public class Program
	{	
		[STAThread]
		static void Main()
		{	
			ObjectServices os = new ObjectServices("engines.config");
			ObjectContext oc = os.CreateObjectContext();

			//Loading all Customers
			IList customers = oc.Load(typeof(Customer));
			
//			//Loading specific Customer from criteria
//			IList customers = oc.Load(typeof(Customer), "[City='London' and ContactName='Hari Kumar']");

			//Loading all Customers and theirs assocated orders (optimize database access)
//			Query query = new Query(typeof(Customer));
//			query.InferredRelationships.Add("Orders");
//			IList customers = oc.Load(query);

			//Loading top 10 Customers and theirs assocated orders (optimize database access)
//			Query query = new Query(typeof(Customer));
//			query.OrderBy.Add("CompanyName");
//			query.InferredRelationships.Add("Orders");
//			query.MaxResults = 10;
//			IList customers = oc.Load(query);

			//Write each loaded Customer (Parent) and its Orders (Children)
			foreach(Customer customer in customers)
			{
				Console.WriteLine(customer.ContactName + " : ");
				foreach(Order order in customer.Orders)
				{
					Console.WriteLine(order.ShipName + ", " + order.OrderDate);
				}
			}

			Console.WriteLine("End of program...");
			Console.ReadLine();
		
		}

	}
}